<link rel="stylesheet" href="${contextPath}/plugins/highlightjs/hljs9.12.0.monokai-sublime.min.css"> 
<!-- <link rel="stylesheet" href="${contextPath}/plugins/highlightjs/hljs9.12.0.default.min.css"> -->
<link rel="stylesheet" href="${contextPath}/plugins/select2/4.0.2/select2.min.css">
<div class="row tab-content-row" id="gen_obj_guide_DIV">
  <div class="col-md-12">
      <div class="box box-primary">
        <div class="box-header">
          <h3 class="box-title">生成器(基于元对象)</h3>
          <div class="box-tools pull-right">
            <form class="form-inline">
            <div class="btn-group" >
                <button type="button" class="btn  btn-success btn-sm" data-btntype="history">历史记录</button>
                <button type="button" class="btn  btn-warning btn-sm" data-btntype="edit" data-position="tool">生成</button>
            </div>
            </form>
          </div>
        </div>
        <!-- /.box-header -->
        <form class="" id="" role="form"  >
        <div class="box-body table-responsive  ">
          
            
            
            <div class="form-group ">
              <div class="col-md-2">
                <select class="" id="obj_selector" name="obj_selector"></select> 
                <div class="box box-solid">
                  <div class="box-header with-border">
                    <h3 class="box-title">对象列表</h3>

                    <div class="box-tools">
                      <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-cloud-download"></i>
                      </button>
                      <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                      </button>
                    </div>
                  </div>
                  <div class="box-body ">
                    <ul class="nav nav-pills nav-stacked">
                      <li><a href="#"><i class="fa fa-sticky-note-o"></i>User
                        <span class="label label-primary pull-right"><i class="fa fa-cog"></i>配置</span>
                        </a>
                      </li>
                      <li><a href="#"><i class="fa fa-sticky-note-o"></i>Org
                        <span class="label label-primary pull-right"><i class="fa fa-cog"></i>配置</span>
                        </a>
                      </li>
                      <li><a href="#"><i class="fa fa-sticky-note-o"></i>Role
                        <span class="label label-primary pull-right"><i class="fa fa-cog"></i>配置</span>
                        </a>
                      </li>
                    </ul>
                  </div>
                  <!-- /.box-body -->
                </div>
                
              </div>
              <div class="col-md-10">
                <div class="nav-tabs-custom" style="min-height: 300px;">
                  <ul class="nav nav-tabs pull-right">
                    
                    <li><a href="#controller_tab" data-toggle="tab"  url="">Controller</a></li>
                    <li><a href="#serviceimpl_tab" data-toggle="tab" url="">ServiceImpl</a></li>
                    <li><a href="#isiervice_tab" data-toggle="tab"  url="">IService</a></li>
                    <li><a href="#dao_tab" data-toggle="tab"  url="">DAO</a></li>
                    <li><a href="#mapper_tab" data-toggle="tab"  url="">Mapper</a></li>
                    <li><a href="#table_tab" data-toggle="tab"  url="">Table</a></li>
                    <li class="active"><a href="#entity_tab" data-toggle="tab"  url="">Entity</a></li>
                    <li class="dropdown">
                      <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        配置 <span class="caret"></span>
                      </a>
                      <ul class="dropdown-menu">
                        <li role="presentation"><a role="menuitem" tabindex="-1" id="pConfig" data-configid="" href="#">项目级配置</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" id="mConfig" data-configid="" href="#">模块级配置</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" id="oConfig" data-configid="" href="#">对象级配置</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" id="aConfig" data-configid="" href="#">属性级配置</a></li>
                        <li role="presentation" class="divider"></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">数据库配置</a></li>
                        <li role="presentation"><a role="menuitem" tabindex="-1" href="#">生成时配置</a></li>
                      </ul>
                    </li>
                    <li class="pull-left header"><i class="fa fa-th"></i> 产品系列</li>
                    
                    
                  </ul>
                  <div class="tab-content">
                    <div class="tab-pane active" id="entity_tab">
                      <div class="box box-solid">
                        <div class="box-header with-border">
                          <h3 class="box-title">代码</h3>
                        </div>
                        <div class="box-body ">
                          <pre>
                            <mycode class="hljs java">
                            
                            </mycode>
                          </pre>
                        </div>
                        <!-- /.box-body -->
                      </div>
                      
                    </div>
                    <!-- /.tab-pane -->
                    <div class="tab-pane" id="table_tab">
                      <div class="box box-solid">
                        <div class="box-header with-border">
                          <select class="" id="db_selector" name="db_selector"></select> 
                        </div>
                        <div class="box-body ">
                          <pre>
                            <mycode class="hljs java">
                            
                            </mycode>
                          </pre>
                        </div>
                        <!-- /.box-body -->
                      </div>
                    </div>
                    <div class="tab-pane" id="mapper_tab">
                      The European languages are members of the same family. Their separate existence is a myth.
                      For science, music, sport, etc, Europe uses the same vocabulary. The languages only differ
                      in their grammar, their pronunciation and their most common words. Everyone realizes why a
                      new common language would be desirable: one could refuse to pay expensive translators. To
                      achieve this, it would be necessary to have uniform grammar, pronunciation and more common
                      words. If several languages coalesce, the grammar of the resulting language is more simple
                      and regular than that of the individual languages.
                    </div>
                    <!-- /.tab-pane -->
                    <div class="tab-pane" id="dao_tab">
                      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                      when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                      It has survived not only five centuries, but also the leap into electronic typesetting,
                      remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
                      like Aldus PageMaker including versions of Lorem Ipsum.
                    </div>
                    <!-- /.tab-pane -->
                    <div class="tab-pane" id="isiervice_tab">
                      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                      when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                      It has survived not only five centuries, but also the leap into electronic typesetting,
                      remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
                      like Aldus PageMaker including versions of Lorem Ipsum.
                    </div>
                    <!-- /.tab-pane -->
                    <div class="tab-pane" id="serviceimpl_tab">
                      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                      when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                      It has survived not only five centuries, but also the leap into electronic typesetting,
                      remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
                      like Aldus PageMaker including versions of Lorem Ipsum.
                    </div>
                    <!-- /.tab-pane -->
                    <div class="tab-pane" id="controller_tab">
                      Lorem Ipsum is simply dummy text of the printing and typesetting industry.
                      Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
                      when an unknown printer took a galley of type and scrambled it to make a type specimen book.
                      It has survived not only five centuries, but also the leap into electronic typesetting,
                      remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset
                      sheets containing Lorem Ipsum passages, and more recently with desktop publishing software
                      like Aldus PageMaker including versions of Lorem Ipsum.
                    </div>
                    <!-- /.tab-pane -->
                  </div>
                  <!-- /.tab-content -->
                </div>
              </div>
            </div>
              
            
            
          
        </div>
        </form>
        <!-- /.box-body -->
        <div class="box-footer box-footer-condensed clearfix">
          <button type="button" class="btn btn-primary" >生成</button>
          <button type="button" class="btn btn-default" >导出</button>
        </div>
          <!-- /.box-footer -->
      </div>
      <!-- /.box -->
  </div>
  <!-- /.col-md-12 -->
  
  
</div>



<script>
  require(["jquery","bootbox","hljs","bootstrap", "bootstrapTable","bootstrapTab_CH","validate","select2","select2_CN","framework"],function($,bootbox,hljs) {
    var container = $("#gen_obj_guide_DIV");
    container.find('#obj_selector').select2({
      ajax: {
          url: "${contextPath}/metaGenObj/queryList",
          dataType: 'json',
          type:'POST',
          data: function (params) {
            
              return {
                  objName: params.term || '', 
                  pageNum: params.pageNum || 1,// search term
                  pageSize: params.pageSize || 3
              };
          },
          processResults: function (data, params) {
                              params.pageNum = data.pageNum || 1;
                              
                              return {
                                  results: data.data.rows,
                                  pagination: {more: (params.pageNum * 3) < data.data.total}
                              };
          },
          cache: true
      },
      language:'zh-CN',
      delay: 250,
      tags:true,
      multiple: true,                      
      allowClear: true,
      placeholder:'请查询或选择元对象',
      width:"100%",
      escapeMarkup: function (markup) { return markup; }, 
      minimumInputLength: 0,
      templateResult: function(repo) {
        if (repo.loading) return repo.text;
        var markup = "<div class='selectorItem' id='"+repo.id+"'>" + (repo.objName || repo.text ) + "</div>";
        return markup;
      }, // omitted for brevity, see the source of this page
      templateSelection: function (repo) {
        if(repo.id){
          return "["+repo.objComment+"("+repo.objName+")]";
        }else{
          return "";
        }
      } // omitted for brevity, see the source of this page
  });
  
  container.find('#obj_selector').on("select2:select", function (e){
      var objId = e.params.data.id;
      $('#obj_selector').data('alTypeId',objId);
      container.find('pre mycode').empty();
      $.ajax({
          type: "POST",
          url: "${contextPath}/gen/preViewEntity",
          dataType:"json",
          //contentType:"application/json",
          async: false,
          data:{"objId":objId},
          success: function(data){
            if("success" == data.status){
              frameworkOptions.clearMessages();
              frameworkOptions.showSuccessMessages(data.message);
              container.find('pre mycode').append(hljs.highlightAuto(data.data.entityCode).value);
            }else if("failure" == data.status){

              if(data.validateMessages){
                frameworkOptions.showValidateMessages(data.validateMessages);
              }else{
                frameworkOptions.showErrorMessages(data.message);
              }
                
            }
              
          }
      });
  });
  function showTabs(targetSelector,url,entityIds,pConfigId,mConfigId,oConfigId,aConfigId){
    $(targetSelector).load(url);

  }
  container.on('click','a[data-toggle="#tab"]',function(e) {
    if((e.currentTarget).attr('url') && ("" != (e.currentTarget).attr('url') )){
      var entityIds = new Array();
      $.each(container.find('#obj_selector').select2('data'),function(index,obj){
        entityIds.push(obj.id);   
      });
      var pConfigId = container.find('#pConfig').data('configid');
      var mConfigId = container.find('#mConfig').data('configid');
      var oConfigId = container.find('#oConfig').data('configid');
      var aConfigId = container.find('#aConfig').data('configid');
      showTabs($(e.currentTarget).attr('href'),(e.currentTarget).attr('url'),entityIds,pConfigId,mConfigId,oConfigId,aConfigId);
      e.preventDefault();
    }
    
  });
  // container.find('pre code').each(function(i, block) {
  //   hljs.highlightBlock(block);
  // });

    
    
  });
</script>